#!/bin/bash


function log_info()
{
    echo "$@"
}

function log_warn()
{
    echo "[WARNING] $@"
}

function log_error()
{
    echo "[ERROR] $@"
    return 1
}

function log_debug()
{
    echo "[DEBUG] $@"
}

safe_run () {
  if ! "$@"; then
    log_error "$* failed; aborting!"
  fi
}

function set_log_level()
{
    log_level='log_level'
    rm -f ./$log_level
    set +e
    sshscp_from "/srv/www/htdocs/$PRE_VERSION/$VERSION/$log_level" .
    if [ $? -ne 0 ]; then
        DEBUG=0
    else
        level=`cat $log_level`
        if [ $level == 'debug' ]; then
            DEBUG=1
        fi
    fi
    set -e
}

function clean_and_exit()
{
    if [ $1 -ne 0 ]; then
        modify_remote_config "BUILD_${SCRIPT}" 3
        echo "=========error start========="
        cat $ERROR_LOG
        exit $1
        echo "=========error end========="
    fi
}

function create_checksum()
{
    file=$1
    sha256sum "$file" > "$file${SHA256SUM}"
}

function init_osc()
{
    set +e
    rm -f /root/.config/osc/trusted-certs/euleros-obs_443.pem
    if which osc &> /dev/null; then
        log_info "osc has been here"
    else
        aarch_type=$(uname -i)
        if [ "x$aarch_type" == "xx86_64" ]; then
            url1="http://10.175.100.158/iso/SLE:/12:/SP2/SLE-12-SP2-SDK-DVD-x86_64-GM-DVD1"
            url2="http://10.175.100.158/iso/SLE:/12:/SP2/SLE-12-SP2-Server-DVD-x86_64-GM-DVD1"

            repo=`zypper lr | awk '{if(NR>2)print $1}'`
            if [ -n "$repo" ];then
                zypper rr $repo
            fi

            zypper ar $url1 sdk
            zypper ar $url2 dvd
            zypper ref -f
            zypper --non-interactive install osc
        elif [ "x$aarch_type" == "xaarch64" ]; then
            wget http://10.175.100.158/OBS:/Server:/2.7/centos7/noarch/osc-0.157.1-202.1.noarch.rpm &> /dev/null
            yum install -y m2crypto
            rpm -ivh osc-0.157.1-202.1.noarch.rpm
        fi
    fi

    cat << EOF > /root/.oscrc
[general]
apiurl = https://euleros-obs
no_verify = 1

[https://euleros-obs]
user=root
pass=EulerOS_123
EOF

    expect -c "
        set timeout 300
        spawn osc ls SUSE:SLE-11:SP3
            expect {
                \"Enter choice*:\" {send \"2\r\"; exp_continue}
            }
    "
    osc ls SUSE:SLE-11:SP3
    if [ $? -ne 0 ]; then
        log_error "failed: when osc ls SUSE:SLE-11:SP3"
    fi
    set -e
}


function check_env()
{
    umask 0022
    rm -f $ERROR_LOG && touch $ERROR_LOG

    if [ "$OBSSERVER_IP" == "10.177.232.213" ];then
        OBSUI_IP="10.177.233.89"
    elif [ "$OBSSERVER_IP" == "100.109.85.100" ];then
        OBSUI_IP="100.109.85.108"
    else
        OBSUI_IP="$OBSSERVER_IP"
    fi

    sed -i '/euleros-obs-repo.huawei.com/d' /etc/hosts
    sed -i '/euleros-obs.huawei.com/d' /etc/hosts
    echo "$OBSSERVER_IP euleros-obs-repo.huawei.com euleros-obs-repo" >> /etc/hosts
    echo "$OBSUI_IP euleros-obs.huawei.com euleros-obs" >> /etc/hosts
}

function chroot_init()
{
    chroot_clean

    rm -f euleros_chroot-*.noarch.rpm
    wget -q -r -l1 -nd -A 'euleros_chroot-*.noarch.rpm' http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/GENERAL:/Custom/standard_$(uname -p)/noarch/ &> /dev/null
    rpm -ivh euleros_chroot-*.noarch.rpm
    rm -f euleros_chroot-*.noarch.rpm
    cp -a ${CPATH}/* "${EULEROS_CHROOT_PATH}/home"
    if echo "$PROJECT_PATH" | grep 'gcov-'; then
        sed -i '/VERSION=/ iexport CI_PROJECT="EulerOS_V200R008C00_ARM64_gcov"' ${EULEROS_CHROOT_PATH}/home/make_version.sh
    fi
    chroot "${EULEROS_CHROOT_PATH}" /bin/bash -c "echo "${OBSSERVER_IP} euleros-obs-repo.huawei.com" >> /etc/hosts"
}

function chroot_clean()
{
    set +e
    rpm -e euleros_chroot
    if [ -d ${EULEROS_CHROOT_PATH} ]; then
        lsof | grep euleros
        for euleros_pid in $(lsof | grep '/usr1/euleros/' | awk '{print $2}')
        do
            kill -9 "${euleros_pid}"
        done
        umount "${EULEROS_CHROOT_PATH}/proc"
        umount "${EULEROS_CHROOT_PATH}/sys"
        umount "${EULEROS_CHROOT_PATH}/dev/pts"
        umount "${EULEROS_CHROOT_PATH}/dev"
        rm -rf "${EULEROS_CHROOT_PATH}"
    fi
    if [ -d ${EULEROS_CHROOT_PATH} ]; then
        log_error "delete ${EULEROS_CHROOT_PATH} failed"
    fi
    set -e
}

function chroot_run()
{
    chroot_init
    chroot "${EULEROS_CHROOT_PATH}" /bin/bash -c "$@"
    chroot_clean
}

function run_script()
{
    script=$1
    shift
    args="$@"
    export SCRIPT="${script}"
    modify_remote_config "BUILD_${SCRIPT}" 1
    log_info "Start run $script $args at `date`"
    eval $script $args
    if [ $? -ne 0 ]; then
        echo "[ERROR]: Run $script $args failed at `date`"
        clean_and_exit 1
    fi
    log_info "Finished run $script $args at `date`"
    modify_remote_config "BUILD_${SCRIPT}" 2
    clean_and_exit 0
}

function run_script_all()
{
    scripts="$@"
    for script in "${all_scripts[@]}"
    do
        run_script $script
    done

}

function chmod_http()
{
    set +e
    release_dir=`get_release_dir`
    SSH_CMD="chmod -R 755 $HTTP_DIR/$PRE_VERSION/$VERSION/${release_dir##*/}"
    sshcmd "$SSH_CMD"
    set -e
}

function set_config_file()
{
    for product in `echo "${PRODUCTS}"`
    do
        cp -a config_temp config_"${product}"
        version_b=${version%_STORAGE_X86}
        if echo "${CI_PROJECT}" | grep gcov &> /dev/null;then
            sed -i "s#^TAR_NAME=.*#TAR_NAME=\"${version}_gcov\"#g" config_"${product}"
            sed -i "s#^VERSION_B=.*#VERSION_B=\"${version_b}_gcov\"#g" config_"${product}"
        else
            sed -i "s#^TAR_NAME=.*#TAR_NAME=\"$version\"#g" config_"${product}"
            sed -i "s#^VERSION_B=.*#VERSION_B=\"${version_b}\"#g" config_"${product}"
        fi
        sed -i "s#^PRODUCT=.*#PRODUCT=\"${product}\"#g" config_"${product}"
        sed -i "s#^TIME=.*#TIME=\"${TIME}\"#g" config_"${product}"
        sed -i "s#^CI_PROJECT=.*#CI_PROJECT=\"${CI_PROJECT}\"#g" config_"${product}"
        sshscp "config_${product}" "$HTTP_DIR/$PRE_VERSION/$VERSION"
    done
}

function modify_remote_config()
{
    ITEM="$1"
    ITEM="${ITEM%_in_docker}"
    STATUS="$2"
    for exclude_script in "${exclude_register_script[@]}"
    do
        if [ "$ITEM" == "BUILD_${exclude_script}" ]; then
            return 0
        fi
    done

    for product in `echo "${PRODUCTS}"`
    do
        RELEASE_CONFIG_FILE="config_${product}"
        SSH_CMD="if cat $HTTP_DIR/$PRE_VERSION/$VERSION/${RELEASE_CONFIG_FILE} | grep \"^${ITEM}\";then sed -i \"s#${ITEM}=.*#${ITEM}=\"${STATUS}\"#g\" $HTTP_DIR/$PRE_VERSION/$VERSION/${RELEASE_CONFIG_FILE};else echo \"${ITEM}=${STATUS}\" >> $HTTP_DIR/$PRE_VERSION/$VERSION/${RELEASE_CONFIG_FILE};fi;chmod -R 755 $HTTP_DIR/$PRE_VERSION/$VERSION/$RELEASE_CONFIG_FILE"
        sshcmd "$SSH_CMD"
    done
}

function get_version()
{
    version_on_web='version'
    rm -f ./$version_on_web
    #wget -q "http://$IP/$PRE_VERSION/$VERSION/$version_on_web" &> /dev/null
    sshscp_from "$HTTP_DIR/$PRE_VERSION/$VERSION/$version_on_web" "./" &> /dev/null
    if [ $? -ne 0 ]; then
        log_error "Failed on wget http://$IP/$PRE_VERSION/$VERSION/$version_on_web"
    fi
    version=`cat $version_on_web`
    [ -z $version ] && log_error "You must set version in config file or from CI web page"
    log_info "version is $version"
    export version=$version
}

function set_release_dir()
{
    set +u
    if [ "x$version_from_jenkins" != "x" ]; then
	version="$(echo $version_from_jenkins |sed s/[[:space:]]//g)"
    elif [ -f $WORK_DIR'version' ]; then
        version=`cat $WORK_DIR'version'`
    else
        version="$MYVERSION"
    fi
    [ -z $version ] && log_error "You must set version in config file or from CI web page"
    log_info "version is $version"
    SSH_CMD="mkdir -p $HTTP_DIR/$PRE_VERSION/$VERSION; echo $version > $HTTP_DIR/$PRE_VERSION/$VERSION/version; chmod 644 $HTTP_DIR/$PRE_VERSION/$VERSION/version"
    sshcmd "$SSH_CMD"
    log_info "echo $version > $HTTP_DIR/$PRE_VERSION/$VERSION/version; chmod 644 $HTTP_DIR/$PRE_VERSION/$VERSION/version"

    if [ -f $WORK_DIR'DEBUG' ]; then
        debug='debug'
    else
        debug='nodebug'
    fi
    log_info "=========log level is DEBUG========="
    SSH_CMD="echo $debug > $HTTP_DIR/$PRE_VERSION/$VERSION/log_level; chmod 644 $HTTP_DIR/$PRE_VERSION/$VERSION/log_level"
    sshcmd "$SSH_CMD"
    log_info "echo $debug > $HTTP_DIR/$PRE_VERSION/$VERSION/log_level; chmod 644 $HTTP_DIR/$PRE_VERSION/$VERSION/log_level"

    release_tmp='release_tmp'
    TIME=`date +%Y-%m-%d-%H-%M-%S`
    TIME_DIR="$PRE_VERSION/$VERSION/$version-$TIME"
    SSH_CMD="echo $HTTP_DIR/$TIME_DIR > $HTTP_DIR/$PRE_VERSION/$VERSION/$release_tmp; chmod 644 $HTTP_DIR/$PRE_VERSION/$VERSION/$release_tmp"
    sshcmd "$SSH_CMD"
    log_info "echo $HTTP_DIR/$TIME_DIR > $HTTP_DIR/$PRE_VERSION/$VERSION/$release_tmp; chmod 644 $HTTP_DIR/$PRE_VERSION/$VERSION/$release_tmp"

    set_config_file
}

function get_release_dir()
{
    release_tmp='release_tmp'
    rm -f ./$release_tmp
    #wget -q "http://$IP/$PRE_VERSION/$VERSION/$release_tmp" &> /dev/null
    sshscp_from "$HTTP_DIR/$PRE_VERSION/$VERSION/$release_tmp" "./" &> /dev/null
    if [ $? -ne 0 ]; then
        log_error "Failed on wget http://$IP/$PRE_VERSION/$VERSION/$release_tmp"
    fi
    echo "`cat $release_tmp`"
}

function trigger_jenkins_project()
{
    jenkins_prj=$1
    product=$2
    set +u
    if [ "x${team_from_jenkins}" != "x" ]; then
        return 0
    fi
    if echo $CI_PROJECT | grep "_gcov" &> /dev/null;then
        return 0
    fi
    if [ "x$product" == "x" ]; then
   	 CMD="curl http://10.175.100.200:8080/jenkins/job//${jenkins_prj}/build?token=xdf"
    else
   	 CMD="curl http://10.175.100.200:8080/jenkins/job/${jenkins_prj}/buildWithParameters?token=xdf -d CONFIG_URL=http://${IP}/${PRE_VERSION}/${VERSION}/config_${product}"
    fi
    eval $CMD
}

function build_and_wait()
{
    get_version
    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}
    TIME=${TIME_DIR##*/}

    if echo "$CI_PROJECT" | grep '_gcov'; then
        update_sys_custom_tool
    fi

    init_osc
    set +eu
    python tools/obs_build.py -s service_list.xml -t 120
    result=$?

    if ! echo "$CI_PROJECT" | grep '_gcov'; then
        PRJS=`cat service_list.xml | grep 'project name' | awk -F'"' '{print $2}' | sort | uniq`
        PRJS=`echo $PRJS | sed 's/ /@/g'`
        curl  ${JENKINS_URL}/job/obs_meta_tags/buildWithParameters?token=xdf -d GERRIT_BRANCH='next' \
              -d GERRIT_OBSLIST="$PRJS" \
              -d GERRIT_DAILYVERSION="$TIME"
    fi
    set -e

    if [ $result -ne 0 ]; then
        log_error "Failed on obs_build"
    else
        log_info "Suessessful on obs_build"
    fi
}


function update_release_info()
{
    if [ $ISCI -eq 0 ]; then
        return 0
    fi
    temp_dir="code_merge_dir"
    pkg="euleros-latest-release"
    obs_pro="EulerOS:V3R1:GENERAL:Custom"

    rm -rf $temp_dir
    mkdir $temp_dir
    cd $temp_dir

    init_osc
    osc co ${obs_pro} ${pkg}
    #overright obs file
    rm -f ${obs_pro}/${pkg}/*
    set +u
    if [ -d ${WORKSPACE}/git/euleros-latest-release ]; then
        cp ${WORKSPACE}/git/euleros-latest-release/euleros-latest-release.spec ${obs_pro}/${pkg}/
        cp ${WORKSPACE}/git/euleros-latest-release/isopackage_arm64.sdf ${obs_pro}/${pkg}/
    else
        cp ${CPATH}/../../../../../euleros-latest-release/euleros-latest-release.spec ${obs_pro}/${pkg}/
        cp ${CPATH}/../../../../../euleros-latest-release/isopackage_arm64.sdf ${obs_pro}/${pkg}/
    fi

    #update sdf file
    get_version
    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}

    TIME=${TIME_DIR##*/}
    TIME=${TIME#$version-}
    echo $version > version

    if [ -d ${WORKSPACE}/git/kernel ]; then
        kver=`rpmspec -q --srpm --qf '%{Version}-%{Release}' ${WORKSPACE}/git/kernel/kernel*.spec`
    else
        kver=`rpmspec -q --srpm --qf '%{Version}-%{Release}' ${CPATH}/../../../../../kernel/kernel*.spec`
    fi

    namer="${kver}"
    if echo $version | grep '_T$' ; then
        dailyversion="${version}-${TIME}"
    else
        dailyversion="$version"
    fi
    sdf_file="${obs_pro}/${pkg}/isopackage_arm64.sdf"
    echo "eulerversion=${dailyversion}" > $sdf_file
    echo "compiletime=${TIME}" >> $sdf_file
    echo "kernelversion=${namer}" >> $sdf_file
    #update end

    #code commit
    cd ${obs_pro}/${pkg}
    osc up
    set +e
    osc add *
    set -e
    osc ci -m "update source code by build_arm64"
    cd $CPATH
    rm -rf $temp_dir
}


function make_iso_debug()
{
    chroot_run "cd /home; bash make_version.sh make_iso_debug_inchroot"
}

function make_iso_debug_inchroot()
{
    get_version
    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}
    TIME=${TIME_DIR##*/}
    TIME=${TIME#$version-}

    yum_conf="${CPATH}/repo_conf/obs-aarch64.conf"
    yum clean all -c $yum_conf
    if rpm -q mkeuleros &> /dev/null; then
       yum remove mkeuleros -y
    fi
    if rpm -q lorax &> /dev/null; then
       yum remove lorax -y
    fi
    yum install mkeuleros lorax -y -c $yum_conf
    cd /opt/mkeuleros

    set +e
    num=0
    while [ $num -lt 3 ]
    do
        bash -x mkeuleros.sh -f config/aarch64/standard.conf -n "EulerOS" -v "V2.0SP8" -s "SP8" -a "aarch64" -r "${OBS_PROJECTS}" -d
        if [ $? -eq 0 ];then
            break
        elif [ $? -eq 133 ]; then
            sleep 60
            ((num=num+1))
            continue
        else
            log_error "make_iso_debug fail"
            break
        fi
    done
    if [ $num -ge 3 ]; then
        log_error "retry make_iso_debug fail"
    fi
    set -e

    cd /result

    TGZ_NAME=`ls *debug-dvd.iso`
    if [ x"$TGZ_NAME" == x'' ]; then
        log_error "can not find iso"
    fi
    create_checksum "$TGZ_NAME"


    #log_info "$HTTP_DIR/$TIME_DIR" > "$WORK_DIR"releasedir_info
    CUSTOM_DIR="${TIME_DIR}/${SUB_RELEASE_DIR}"
    RELEASE_DIR="$HTTP_DIR/$CUSTOM_DIR"
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"
    sshscp "$TGZ_NAME $TGZ_NAME${SHA256SUM} " "$RELEASE_DIR"

    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    log_info "Release iso to http://$IP/$CUSTOM_DIR/"

    release_file="release_iso_debug"
    SSH_CMD="echo http://$IP/$CUSTOM_DIR/$TGZ_NAME > $HTTP_DIR/$PRE_VERSION/$VERSION/$release_file; chmod 644 $HTTP_DIR/$PRE_VERSION/$VERSION/$release_file"
    sshcmd "$SSH_CMD"
    log_info "echo http://$IP/$CUSTOM_DIR/$TGZ_NAME > $release_file"

    if [ $ISCI -eq 0 ]; then
        return 0
    fi

    mkdir -pv "$WORK_DIR"output
    html="$WORK_DIR"output/release_iso_debug.html
    cat /dev/null > $html
    echo "<html><body>" >> $html
    echo '<div style="border: 1px solid;background-color:PowderBlue;text-align:;height:200px;width:100%">' >> $html
    echo "<h1>The newest $VERSION Release</h1>" >> $html
    echo "The release is created on `date`" >> $html
    echo "<h3>Download on windows: <a href=\"http://$IP/$CUSTOM_DIR/$TGZ_NAME\" target='_blank'>$TGZ_NAME</a><br />" >> $html
    echo "<p>Download on linux: run \"wget http://$IP/$CUSTOM_DIR/$TGZ_NAME\"</p>" >> $html
    echo "<p>View the history version, please go to : <a href=\"http://$IP/$PRE_VERSION/$VERSION\" target='_blank'>http://$IP/$PRE_VERSION/$VERSION/</a></p></h3></div>" >> $html
    echo "<br />" >> $html
    echo "</div></body></html>" >> $html

    set +e
    sshscp "$html" "$HTTP_DIR/$PRE_VERSION/$VERSION"
    SSH_CMD="chmod 755 $HTTP_DIR/$PRE_VERSION/$VERSION/${html##*/}"
    sshcmd "$SSH_CMD"
    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    set -e

    return 0
}


function make_iso()
{
    chroot_run "cd /home; bash make_version.sh make_iso_inchroot"
}


function make_iso_inchroot()
{
    get_version
    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}
    TIME=${TIME_DIR##*/}
    TIME=${TIME#$version-}

    yum_conf="${CPATH}/repo_conf/obs-aarch64.conf"
    yum clean all -c $yum_conf
    if rpm -q mkeuleros &> /dev/null; then
       yum remove mkeuleros -y
    fi
    if rpm -q lorax &> /dev/null; then
       yum remove lorax -y
    fi
    yum install mkeuleros lorax -y -c $yum_conf
    cd /opt/mkeuleros

    set +e
    num=0
    while [ $num -lt 3 ]
    do
        bash -x mkeuleros.sh -f config/aarch64/standard.conf -n "EulerOS" -v "V2.0SP8" -s "SP8" -a "aarch64" -r "${OBS_PROJECTS}"
        if [ $? -eq 0 ];then
            break
        elif [ $? -eq 133 ]; then
            sleep 60
            ((num=num+1))
            continue
        else
            log_error "make_iso fail"
            break
        fi
    done
    if [ $num -ge 3 ]; then
        log_error "retry make_iso fail"
    fi
    set -e

    cd /result

    TGZ_NAME=`ls *aarch64-dvd.iso`
    if [ x"$TGZ_NAME" == x'' ]; then
        log_error "can not find iso"
    fi
    create_checksum "$TGZ_NAME"

    #public src iso
    SRC_NAME=`ls *source-dvd.iso`
    if [ x"$SRC_NAME" == x'' ]; then
        log_error "can not find iso"
    fi
    create_checksum "$SRC_NAME"
    #end

    #log_info "$HTTP_DIR/$TIME_DIR" > "$WORK_DIR"releasedir_info
    CUSTOM_DIR="${TIME_DIR}/${SUB_RELEASE_DIR}"
    RELEASE_DIR="$HTTP_DIR/$CUSTOM_DIR"
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"
    sshscp "$TGZ_NAME $TGZ_NAME${SHA256SUM} $SRC_NAME $SRC_NAME${SHA256SUM}" "$RELEASE_DIR"

    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    log_info "Release iso to http://$IP/$CUSTOM_DIR/"

    release_file="release_iso"
    SSH_CMD="echo http://$IP/$CUSTOM_DIR/$TGZ_NAME > $HTTP_DIR/$PRE_VERSION/$VERSION/$release_file; chmod 644 $HTTP_DIR/$PRE_VERSION/$VERSION/$release_file"
    sshcmd "$SSH_CMD"
    log_info "echo http://$IP/$CUSTOM_DIR/$TGZ_NAME > $release_file"

    if [ $ISCI -eq 0 ]; then
        return 0
    fi

    mkdir -pv "$WORK_DIR"output
    html="$WORK_DIR"output/release_iso.html
    cat /dev/null > $html
    echo "<html><body>" >> $html
    echo '<div style="border: 1px solid;background-color:PowderBlue;text-align:;height:200px;width:100%">' >> $html
    echo "<h1>The newest $VERSION Release</h1>" >> $html
    echo "The release is created on `date`" >> $html
    echo "<h3>Download on windows: <a href=\"http://$IP/$CUSTOM_DIR/$TGZ_NAME\" target='_blank'>$TGZ_NAME</a><br />" >> $html
    echo "<p>Download on linux: run \"wget http://$IP/$CUSTOM_DIR/$TGZ_NAME\"</p>" >> $html
    echo "<p>View the history version, please go to : <a href=\"http://$IP/$PRE_VERSION/$VERSION\" target='_blank'>http://$IP/$PRE_VERSION/$VERSION/</a></p></h3></div>" >> $html
    echo "<br />" >> $html
    echo "</div></body></html>" >> $html

    set +e
    sshscp "$html" "$HTTP_DIR/$PRE_VERSION/$VERSION"
    SSH_CMD="chmod 755 $HTTP_DIR/$PRE_VERSION/$VERSION/${html##*/}"
    sshcmd "$SSH_CMD"
    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    set -e

    return 0
}


function make_tar()
{
    chroot_run "cd /home; bash make_version.sh make_tar_inchroot"
}


function make_tar_inchroot()
{
    get_version
    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}

    TIME=${TIME_DIR##*/}
    TIME=${TIME#$version-}

    result_dir="/home/ci_workdir/EulerOS"

    [ -d $result_dir ] && rm -rf ${result_dir}/*

    yum_conf="${CPATH}/repo_conf/obs-aarch64.conf"
    yum clean all -c $yum_conf
    if rpm -q sys-custom-tool &> /dev/null; then
        yum remove sys-custom-tool -y
    fi
    yum install sys-custom-tool -y -c $yum_conf
    cd /opt/local_script/
    bash make_version.sh make_tar_aarch64 -v $version -t $TIME
    cd -

    TGZ_NAME=`ls ${result_dir}/*.tar.gz`
    if [ $? -ne 0 ]; then
        log_error "Tar $KIWITOOL_DIR into $version.tar.gz failed"
    fi
    create_checksum "$TGZ_NAME"

    CUSTOM_DIR="${TIME_DIR}/${SUB_RELEASE_DIR}"
    RELEASE_DIR="$HTTP_DIR/$CUSTOM_DIR"
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"
    sshscp "$TGZ_NAME $TGZ_NAME${SHA256SUM}" "$RELEASE_DIR"

    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    log_info "Release iso to http://$IP/$CUSTOM_DIR/"

    release_file="release"
    SSH_CMD="echo http://$IP/$CUSTOM_DIR/${TGZ_NAME##*/} > $HTTP_DIR/$PRE_VERSION/$VERSION/$release_file; chmod 644 $HTTP_DIR/$PRE_VERSION/$VERSION/$release_file"
    sshcmd "$SSH_CMD"
    log_info "echo http://$IP/$CUSTOM_DIR/${TGZ_NAME##*/} > $release_file"

    if [ $ISCI -eq 0 ]; then
        return 0
    fi
    mkdir -pv "$WORK_DIR"output
    html="$WORK_DIR"output/release_tar.html
    cat /dev/null > $html
    echo "<html><body>" >> $html
    echo '<div style="border: 1px solid;background-color:PowderBlue;text-align:;height:200px;width:100%">' >> $html
    echo "<h1>The newest $VERSION Release</h1>" >> $html
    echo "The release is created on `date`" >> $html
    echo "<h3>Download on windows: <a href=\"http://$IP/$CUSTOM_DIR/${TGZ_NAME##*/}\" target='_blank'>${TGZ_NAME##*/}</a><br />" >> $html
    echo "<p>Download on linux: run \"wget http://$IP/$CUSTOM_DIR/${TGZ_NAME##*/}\"</p>" >> $html
    echo "<p>View the history version, please go to : <a href=\"http://$IP/$PRE_VERSION/$VERSION\" target='_blank'>http://$IP/$PRE_VERSION/$VERSION/</a></p></h3></div>" >> $html
    echo "<br />" >> $html
    echo "</div></body></html>" >> $html

    set +e
    sshscp "$html" "$HTTP_DIR/$PRE_VERSION/$VERSION"
    SSH_CMD="chmod 755 $HTTP_DIR/$PRE_VERSION/$VERSION/${html##*/}"
    sshcmd "$SSH_CMD"
    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    set -e
    return 0
}


function make_tar_pangea()
{
    chroot_run "cd /home; bash make_version.sh make_tar_pangea_inchroot"
}


function make_tar_pangea_inchroot()
{
    get_version
    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}

    TIME=${TIME_DIR##*/}
    TIME=${TIME#$version-}

    result_dir="/home/ci_workdir/EulerOS"

    [ -d $result_dir ] && rm -rf ${result_dir}/*

    yum_conf="${CPATH}/repo_conf/obs-pangea.conf"
    yum clean all -c $yum_conf
    if rpm -q sys-custom-tool &> /dev/null; then
        yum remove sys-custom-tool -y
    fi
    yum install sys-custom-tool -y -c $yum_conf
    cd /opt/local_script/
    bash make_version.sh make_tar_pangea_aarch64 -v $version -t $TIME
    cd -

    TGZ_NAME=`ls ${result_dir}/*.tar.gz`
    if [ $? -ne 0 ]; then
        log_error "Tar $KIWITOOL_DIR into $version.tar.gz failed"
    fi
    create_checksum "$TGZ_NAME"

    CUSTOM_DIR="${TIME_DIR}/${SUB_RELEASE_DIR}"
    RELEASE_DIR="$HTTP_DIR/$CUSTOM_DIR"
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"
    sshscp "$TGZ_NAME $TGZ_NAME${SHA256SUM}" "$RELEASE_DIR"

    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    log_info "Release iso to http://$IP/$CUSTOM_DIR/"

    release_file="release"
    SSH_CMD="echo http://$IP/$CUSTOM_DIR/${TGZ_NAME##*/} > $HTTP_DIR/$PRE_VERSION/$VERSION/$release_file; chmod 644 $HTTP_DIR/$PRE_VERSION/$VERSION/$release_file"
    sshcmd "$SSH_CMD"
    log_info "echo http://$IP/$CUSTOM_DIR/${TGZ_NAME##*/} > $release_file"

    if [ $ISCI -eq 0 ]; then
        return 0
    fi
    mkdir -pv "$WORK_DIR"output
    html="$WORK_DIR"output/release_tar.html
    cat /dev/null > $html
    echo "<html><body>" >> $html
    echo '<div style="border: 1px solid;background-color:PowderBlue;text-align:;height:200px;width:100%">' >> $html
    echo "<h1>The newest $VERSION Release</h1>" >> $html
    echo "The release is created on `date`" >> $html
    echo "<h3>Download on windows: <a href=\"http://$IP/$CUSTOM_DIR/${TGZ_NAME##*/}\" target='_blank'>${TGZ_NAME##*/}</a><br />" >> $html
    echo "<p>Download on linux: run \"wget http://$IP/$CUSTOM_DIR/${TGZ_NAME##*/}\"</p>" >> $html
    echo "<p>View the history version, please go to : <a href=\"http://$IP/$PRE_VERSION/$VERSION\" target='_blank'>http://$IP/$PRE_VERSION/$VERSION/</a></p></h3></div>" >> $html
    echo "<br />" >> $html
    echo "</div></body></html>" >> $html

    set +e
    sshscp "$html" "$HTTP_DIR/$PRE_VERSION/$VERSION"
    SSH_CMD="chmod 755 $HTTP_DIR/$PRE_VERSION/$VERSION/${html##*/}"
    sshcmd "$SSH_CMD"
    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    set -e
    return 0
}


function make_compile_env_arm_common()
{
    chroot_run "cd /home; bash make_version.sh make_compile_env_arm_common_inchroot"
}


function make_compile_env_arm_common_inchroot()
{
    get_version
    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}

    TIME=${TIME_DIR##*/}
    TIME=${TIME#$version-}

    yum -c ${CPATH}/repo_conf/obs-aarch64.conf clean all
    if rpm -q sys-custom-tool &> /dev/null; then
        yum remove sys-custom-tool -y
    fi
    yum install -y sys-custom-tool -c ${CPATH}/repo_conf/obs-aarch64.conf
    cd /opt/local_script/
    bash make_version.sh make_compile_env_aarch64 -v $version -t $TIME -p 'standard'
    if [ $? -ne 0 ]; then
        result=1
        log_error "Failed on $0"
    else
        result=0
        log_info "Suessessful on $0"
    fi

    COMPILE_ENV="Euler_compile_env"
    COMPILE_ENV_FOR_DOCKER=${COMPILE_ENV}_for_docker
    RELEASEDIR=`get_release_dir`
    RELEASE_DIR="${RELEASEDIR}/${SUB_RELEASE_DIR}/CompileTools/"

    create_checksum $COMPILE_ENV.tar.gz
    create_checksum $COMPILE_ENV_FOR_DOCKER.tar.gz
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"

    sshscp "$COMPILE_ENV.tar.gz $COMPILE_ENV.tar.gz${SHA256SUM}" "$RELEASE_DIR"
    sshscp "$COMPILE_ENV_FOR_DOCKER.tar.gz $COMPILE_ENV_FOR_DOCKER.tar.gz${SHA256SUM}" "$RELEASE_DIR"
    rm -f $COMPILE_ENV.tar.gz $COMPILE_ENV.tar.gz${SHA256SUM}
    rm -f $COMPILE_ENV_FOR_DOCKER.tar.gz $COMPILE_ENV_FOR_DOCKER.tar.gz${SHA256SUM}
    chmod_http
    if [ $? -ne 0 ]; then
        result=1
        log_error "Failed in chmod_http"
    fi
    log_info "Release $COMPILE_ENV to $IP:$RELEASE_DIR"
    return $result
}


function make_compile_env_arm_storage()
{
    chroot_run "cd /home; bash make_version.sh make_compile_env_arm_storage_inchroot"
}


function make_compile_env_arm_storage_inchroot()
{
    get_version
    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}

    TIME=${TIME_DIR##*/}
    TIME=${TIME#$version-}

    yum -c ${CPATH}/repo_conf/obs-aarch64.conf clean all
    if rpm -q sys-custom-tool &> /dev/null; then
        yum remove sys-custom-tool -y
    fi
    yum install -y sys-custom-tool -c ${CPATH}/repo_conf/obs-aarch64.conf
    cd /opt/local_script/
    bash make_version.sh make_compile_env_storage_aarch64 -v $version -t $TIME -p 'standard'
    if [ $? -ne 0 ]; then
        result=1
        log_error "Failed on $0"
    else
        result=0
        log_info "Suessessful on $0"
    fi

    COMPILE_ENV="Euler_compile_env_storage"
    RELEASEDIR=`get_release_dir`
    RELEASE_DIR="${RELEASEDIR}/${SUB_RELEASE_DIR}/CompileTools/"

    create_checksum $COMPILE_ENV.tar.gz
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"

    sshscp "$COMPILE_ENV.tar.gz $COMPILE_ENV.tar.gz${SHA256SUM}" "$RELEASE_DIR"
    rm -f $COMPILE_ENV.tar.gz $COMPILE_ENV.tar.gz${SHA256SUM}
    chmod_http
    if [ $? -ne 0 ]; then
        result=1
        log_error "Failed in chmod_http"
    fi
    log_info "Release $COMPILE_ENV to $IP:$RELEASE_DIR"
    return $result
}

function get_arm_chroot_standard()
{
    rm -rf sys-custom-tool-*.noarch.rpm
    wget -q -r -l1 -nd -A 'sys-custom-tool-*.noarch.rpm' http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/GENERAL:/Custom/standard_aarch64/noarch/ &> /dev/null
    sshcmd_arm "mkdir -p /usr1/CI; rm -rf /usr1/CI/*"
    sshscp_arm sys-custom-tool-*.noarch.rpm "/usr1/CI"
    sshcmd_arm "cd /usr1/CI; rpm2cpio sys-custom-tool-*.noarch.rpm |cpio -dim"
    sshcmd_arm "cd /usr1/CI/opt/local_script; flock -x /var/lock/compile_env.lock -c  'bash -x make_version.sh make_compile_env_common -p standard > arm_cross.log 2>&1'"
}

function make_compile_env_cross()
{
    chroot_run "cd /home; bash make_version.sh make_compile_env_cross_inchroot"
}


function make_compile_env_cross_inchroot()
{
    get_arm_chroot_standard &
    get_version
    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}

    TIME=${TIME_DIR##*/}
    TIME=${TIME#$version-}

    yum -c ${CPATH}/repo_conf/obs-x86_64.conf clean all
    if rpm -q sys-custom-tool &> /dev/null; then
        yum remove sys-custom-tool -y
    fi
    yum install -y sys-custom-tool -c ${CPATH}/repo_conf/obs-x86_64.conf
    cd /opt/local_script/
    bash make_version.sh make_compile_env_common -v $version -t $TIME -p 'standard'
    if [ $? -ne 0 ]; then
        result=1
        log_error "Failed on $0"
    else
        result=0
        log_info "Suessessful on $0"
    fi

    wait
    sshscp_from_arm "/usr1/CI/opt/local_script/arm_cross.log" .
    set +e
    LASTLINE=$(tail -1 arm_cross.log)
    grep "No package" arm_cross.log > /dev/null
    if [ $? -eq 0 -o "$LASTLINE" != "+ exit 0" ];then
        cat arm_cross.log
        log_error "Failed on arm_host"
        result=1
    else
        result=0
        log_info "Suessessful on arm_host"
    fi
    set -e
    sshscp_from_arm "/usr1/CI/opt/local_script/Euler_compile_env_aarch64.tar.gz" .
    tar -xf Euler_compile_env_aarch64.tar.gz

    bash make_version.sh make_compile_env_cross -o "GENERAL" -v $version -p 'standard'

    COMPILE_ENV="Euler_compile_env_cross"
    RELEASEDIR=`get_release_dir`
    RELEASE_DIR="${RELEASEDIR}/${SUB_RELEASE_DIR}/CompileTools/"

    create_checksum $COMPILE_ENV.tar.gz
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"

    sshscp "$COMPILE_ENV.tar.gz $COMPILE_ENV.tar.gz${SHA256SUM}" "$RELEASE_DIR"
    rm -f $COMPILE_ENV.tar.gz $COMPILE_ENV.tar.gz${SHA256SUM}
    chmod_http
    if [ $? -ne 0 ]; then
        result=1
        log_error "Failed in chmod_http"
    fi
    log_info "Release $COMPILE_ENV to $IP:$RELEASE_DIR"
    return $result
}

function get_arm_chroot_storage()
{
    rm -rf sys-custom-tool-*.noarch.rpm
    wget -q -r -l1 -nd -A 'sys-custom-tool-*.noarch.rpm' http://${OBSSERVER_IP}:82/EulerOS:/V3R1:/PANGEA:/Custom/standard_aarch64/noarch/ &> /dev/null
    sshcmd_arm "mkdir -p /usr1/CI_storage; rm -rf /usr1/CI_storage/*"
    sshscp_arm sys-custom-tool-*.noarch.rpm "/usr1/CI_storage"
    sshcmd_arm "cd /usr1/CI_storage; rpm2cpio sys-custom-tool-*.noarch.rpm |cpio -dim"
    sshcmd_arm "cd /usr1/CI_storage/opt/local_script; flock -x /var/lock/compile_env.lock -c 'bash -x make_version.sh make_compile_env_common -p storage > arm_cross.log 2>&1'"
}

function make_compile_env_cross_storage()
{
    chroot_run "cd /home; bash make_version.sh make_compile_env_cross_storage_inchroot"
}


function make_compile_env_cross_storage_inchroot()
{
    get_arm_chroot_storage &
    get_version
    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}

    TIME=${TIME_DIR##*/}
    TIME=${TIME#$version-}

    yum -c ${CPATH}/repo_conf/obs-pangea-x86_64.conf clean all
    if rpm -q sys-custom-tool &> /dev/null; then
        yum remove sys-custom-tool -y
    fi
    yum install -y sys-custom-tool -c ${CPATH}/repo_conf/obs-pangea-x86_64.conf
    cd /opt/local_script/
    bash make_version.sh make_compile_env_common -v $version -t $TIME -p 'storage'
    if [ $? -ne 0 ]; then
        result=1
        log_error "Failed on $0"
    else
        result=0
        log_info "Suessessful on $0"
    fi

    wait
    sshscp_from_arm "/usr1/CI_storage/opt/local_script/arm_cross.log" .
    set +e
    LASTLINE=$(tail -1 arm_cross.log)
    grep "No package" arm_cross.log > /dev/null
    if [ $? -eq 0 -o "$LASTLINE" != "+ exit 0" ];then
        cat arm_cross.log
        log_error "Failed on arm_host"
        result=1
        return $result
    else
        result=0
        log_info "Suessessful on arm_host"
    fi
    set -e
    sshscp_from_arm "/usr1/CI_storage/opt/local_script/Euler_compile_env_aarch64.tar.gz" .
    tar -xf Euler_compile_env_aarch64.tar.gz

    bash make_version.sh make_compile_env_cross -o "PANGEA" -v $version -p 'storage'

    COMPILE_ENV="Euler_compile_env_cross_storage"
    RELEASEDIR=`get_release_dir`
    RELEASE_DIR="${RELEASEDIR}/${SUB_RELEASE_DIR}/CompileTools/"

    create_checksum $COMPILE_ENV.tar.gz
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"

    sshscp "$COMPILE_ENV.tar.gz $COMPILE_ENV.tar.gz${SHA256SUM}" "$RELEASE_DIR"
    rm -f $COMPILE_ENV.tar.gz $COMPILE_ENV.tar.gz${SHA256SUM}

    chmod_http
    if [ $? -ne 0 ]; then
        result=1
        log_error "Failed in chmod_http"
    fi
    log_info "Release $COMPILE_ENV to $IP:$RELEASE_DIR"
    return $result
}

function createrepo_EulerOS_ALL()
{
    basedir="/srv/obs/repos/EulerOS_ALL_V3R1"
    product="${ISO_NAME}-${ISO_VERSION}"
    if ls . | grep -E "mkeuleros-*.noarch.rpm" &> /dev/null;then
        rm -f mkeuleros-*.noarch.rpm
    fi
    [ -d ./opt ] && rm -rf ./opt
    wget -q -r -l1 -nd -A 'mkeuleros-*.noarch.rpm' ${obs_custom_url}noarch/ &> /dev/null
    rpm2cpio mkeuleros-*.noarch.rpm | cpio -id
    sh ${TOOLS}/safe_sshcmd.sh -c "if \[ -d ${basedir}/${product} \];then    \
        echo 'The dir is exist';else mkdir -p ${basedir}/${product};fi;" -m $OBSSERVER_IP -u $USER -p $OBSPASSWD
    sh ${TOOLS}/safe_sshscp.sh -p $OBSPASSWD -s "./opt/mkeuleros/config/aarch64/normal.xml" -d $OBSSERVER_IP:${basedir}/${product}
    sh ${TOOLS}/safe_sshcmd.sh -c "\
        thread_info=\`ps aux | grep \"createrepo\" | grep \"${basedir}/${product}\" | grep -v \"grep\"\`;\
        echo \"thread_info= \${thread_info}\";\
        if \[ \"x\$thread_info\" = \"x\" \];then \
            echo \" No process about createrepo\";\
        else \
            temp_dir=\`echo \$thread_info | awk '{print \$16}'\`;\
            echo \"temp_dir= \$temp_dir\";\
            if \[ \"x\$temp_dir\" = \"x${basedir}/${product}/\" \];then \
                echo \"wait for createrepo\";\
                while ps aux | grep \"createrepo\" | grep \"${basedir}/${product}\" | grep -v \"grep\"\ > /dev/null;\
                do \
                    sleep 60;\
                done; \
                exit 0;\
            fi;\
        fi;\
        cd ${basedir}/${product};\
        for path in $livecd_repo; \
        do \
            link_name=\`echo \$path | awk -F '#' '{print \$1}'\`;\
            link_path=\`echo \$path | awk -F '#' '{print \$2}'\`;\
            name=\`ls -l | grep \"\$link_name\" | awk '{print \$9}'\`;\
            path=\`ls -l | grep \"\$link_name\" | awk '{print \$11}'\`;\
            if \[ \"x\$name\" = \"x\$link_name\" \];then \
                if \[ \"x\$path\" = \"x\$link_path\" \];then \
                    continue;\
                else \
                    rm -f \$link_name;\
                    ln -sf \$link_path \$link_name;\
                fi;\
            else \
                ln -sf \$link_path \$link_name;\
            fi;\
        done;\
        set +e; \
        result=0; \
        if \[ -d repodata \];then    \
            echo 'createrepo -g normal.xml ${basedir}/${product}/ --update';\
            createrepo -g normal.xml ${basedir}/${product}/ --update;\
            if \[ \$? -ne 0 \];then   \
                result=1; \
            fi;\
        else    \
            echo 'createrepo -g normal.xml ${basedir}/${product}/';\
            createrepo -g normal.xml ${basedir}/${product}/;\
            if \[ \$? -ne 0 \];then   \
                result=2; \
            fi;\
        fi;\
        if \[ \$result != 0 \];then    \
            for num in \$(echo \"1 2 3 4 5\" | xargs); \
            do \
                sleep 60; \
                if \[ \$result = 1 \];then    \
                    createrepo -g normal.xml ${basedir}/${product}/ --update;\
                elif \[ \$result = 2 \];then    \
                    createrepo -g normal.xml ${basedir}/${product}/;\
                fi;\
                if \[ \$? eq 0 \];then    \
                    break; \
                fi; \
            done; \
        fi; \
        set -e;" -m ${OBSSERVER_IP} -u ${USER} -p ${OBSPASSWD}
}

function make_livecd()
{
    chroot_run "cd /home; bash make_version.sh make_livecd_inchroot"
}

function make_livecd_inchroot()
{
    set -ex
    rm -rf /etc/yum.repos.d/* || true
    if [ ! -d /etc/yum.repos.d/ ]; then
         mkdir -p /etc/yum.repos.d
    fi
    cat repo_conf/obs-aarch64.conf > /etc/yum.repos.d/EnCloudOS.repo

    yum clean all
    yum install -y lorax anaconda yum-langpacks libselinux-utils

    createrepo_EulerOS_ALL

    set +e
    setenforce 0
    set -e

    sed -i "s/PRODUCT_NAME/$ISO_NAME-$ISO_VERSION/" $CPATH/euleros-livecd.ks
    rm -rf /usr/share/lorax/templates.d/99-generic/live && cp -r live /usr/share/lorax/templates.d/99-generic/
    mkdir -p `pwd`/tmp
    livemedia-creator --make-iso --ks=`pwd`/euleros-livecd.ks --nomacboot --no-virt --project $ISO_NAME --releasever $ISO_VERSION --tmp `pwd`/tmp --anaconda-arg="--nosave=all_ks"

    rm -rf /etc/yum.repos.d/EnCloudOS.repo || true

    #Release ISO to 158
    get_version
    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}

    cd tmp/*/images
    LIVECD_NAME="EulerOS_minios_livecd.iso"
    LIVECD_TAR=`ls *.iso`
    mv $LIVECD_TAR $LIVECD_NAME

    create_checksum "$LIVECD_NAME"
    CUSTOM_DIR="$TIME_DIR/$SUB_RELEASE_DIR/"
    RELEASE_DIR="$HTTP_DIR/$CUSTOM_DIR"
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"
    sshscp "$LIVECD_NAME $LIVECD_NAME${SHA256SUM}" "$RELEASE_DIR"

    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    log_info "Release iso to http://$IP/$CUSTOM_DIR/"

    cd -
    rm -rf *.log
    rm -rf anaconda
    rm -rf tmp

    release_file="release_livecd"
    SSH_CMD="echo http://$IP/$CUSTOM_DIR/$LIVECD_NAME > $HTTP_DIR/$PRE_VERSION/$VERSION/$release_file; chmod 644 $HTTP_DIR/$PRE_VERSION/$VERSION/$release_file"
    sshcmd "$SSH_CMD"
    log_info "echo http://$IP/$CUSTOM_DIR/$LIVECD_NAME > $release_file"

    mkdir -pv "$WORK_DIR"output
    html="$WORK_DIR"output/release_livecd.html
    cat /dev/null > $html
    echo "<html><body>" >> $html
    echo '<div style="border: 1px solid;background-color:PowderBlue;text-align:;height:200px;width:100%">' >> $html
    echo "<h1>The newest $VERSION Release</h1>" >> $html
    echo "The release is created on `date`" >> $html
    echo "<h3>Download on windows: <a href=\"http://$IP/$CUSTOM_DIR/$LIVECD_NAME\" target='_blank'>$LIVECD_NAME</a><br />" >> $html
    echo "<p>Download on linux: run \"wget http://$IP/$CUSTOM_DIR/$LIVECD_NAME\"</p>" >> $html
    echo "<p>View the history version, please go to : <a href=\"http://$IP/$PRE_VERSION/$VERSION\" target='_blank'>http://$IP/$PRE_VERSION/$VERSION/</a></p></h3></div>" >> $html
    echo "<br />" >> $html
    echo "</div></body></html>" >> $html

    set +e
    sshscp "$html" "$HTTP_DIR/$PRE_VERSION/$VERSION"
    SSH_CMD="chmod 755 $HTTP_DIR/$PRE_VERSION/$VERSION/${html##*/}"
    sshcmd "$SSH_CMD"
    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    set -e
    return 0
}

function make_HMI()
{
    chroot_run "cd /home; bash make_version.sh make_HMI_inchroot"
}

function make_HMI_inchroot()
{
    get_version
    RESULT_HMI="/usr1/mkeuleros/result_hmi"
    [ -d ${RESULT_HMI} ] && rm -rf ${RESULT_HMI}/*
    mkdir -p ${RESULT_HMI}

    HMI_REPOS=`echo $OBS_PROJECTS | sed 's/ / -r /g'`
    yum -c /home/repo_conf/obs-aarch64.conf clean all
    yum install -y CreateImage sudo parted dosfstools e2fsprogs -c /home/repo_conf/obs-aarch64.conf
    pushd ${RESULT_HMI}; create-image -r $HMI_REPOS; mv system.img ${version}-hmi.raw; qemu-img convert ${version}-hmi.raw -O qcow2 ${version}-hmi.qcow2; xz ${version}-hmi.raw; xz ${version}-hmi.qcow2;popd
    cd ${RESULT_HMI}

    TGZ_RAW=`ls *.raw.xz`
    create_checksum "$TGZ_RAW"
    TGZ_QCOW2=`ls *.qcow2.xz`
    create_checksum "$TGZ_QCOW2"
## end

    release_dir=`get_release_dir`
    TIME_DIR=${release_dir#/srv/www/htdocs/}

    TIME=${TIME_DIR##*/}
    TIME=${TIME#$version-}

    TIME_DIR="$PRE_VERSION/$VERSION/$version-${TIME}"
    CUSTOM_DIR="$TIME_DIR/$SUB_RELEASE_DIR"
    RELEASE_DIR="$HTTP_DIR/$CUSTOM_DIR"
    SSH_CMD="mkdir -p $RELEASE_DIR"

    sshcmd "$SSH_CMD"
    sshscp "$TGZ_RAW $TGZ_RAW${SHA256SUM} $TGZ_QCOW2 $TGZ_QCOW2${SHA256SUM}" "$RELEASE_DIR"

    chmod_http
    #HMI_tar_name BUILD_make_HMI
    return 0
}
function make_euleros_certdb()
{
    [[ -d $WORK_DIR ]] || mkdir -p $WORK_DIR
    CERTDB_DIR=$WORK_DIR"euleros-certdb_dir"
    [[ -d $CERTDB_DIR ]] || mkdir -p $CERTDB_DIR
    cd $CERTDB_DIR
    wget -q -r -l1 -nd -A 'euleros-certdb-1*.noarch.rpm' ${obs_kernel_noarch_url}
    if ls $CERTDB_DIR/euleros-certdb-1*.noarch.rpm
    then
        CERTDB_RPM=`ls $CERTDB_DIR/euleros-certdb-1*.noarch.rpm`
        release_dir=`get_release_dir`
        RELEASE_DIR="${release_dir}/${SUB_RELEASE_DIR}/CompileTools/"
        SSH_CMD="mkdir -p $RELEASE_DIR"
        sshcmd "$SSH_CMD"
        sshscp "$CERTDB_RPM" "$RELEASE_DIR"
        [[ -d $CERTDB_DIR ]] && rm -rf $CERTDB_DIR
    else
        [[ -d $CERTDB_DIR ]] || rm -rf $CERTDB_DIR
        log_error "Failed on wget euleros-certdb-1*.noarch.rpm"
    fi
}

function make_compile_tools()
{
    [[ -d $WORK_DIR ]] || mkdir -p $WORK_DIR
    REPO=$WORK_DIR"compile_tools"
    #RPM_PATH="$PROJECT_PATH/repo_other"

    [ -d $REPO ] && rm -rf $REPO
    python $TOOLS/repo_maker.py -f compile_tools.xml -d $REPO -p "${OBSSERVER_IP}:82"
    if [ $? -ne 0 ]; then
        log_error "Failed on repo_make compile_tools.xml"
    else
        log_info "Suessessful on repo_make compile_tools.xml"
    fi
    cd $WORK_DIR
    TGZ_NAME=compile_tools
    tar czf ${TGZ_NAME}.tar.gz ${TGZ_NAME}
    create_checksum "$TGZ_NAME".tar.gz
    release_dir=`get_release_dir`
    RELEASE_DIR="${release_dir}/${SUB_RELEASE_DIR}/CompileTools/"
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"
    sshscp "${TGZ_NAME}.tar.gz ${TGZ_NAME}.tar.gz${SHA256SUM}" "$RELEASE_DIR"

}


function mkdliso_HyperStackOS()
{
    chroot_run "cd /home; bash make_version.sh mkdliso_HyperStackOS_inchroot"
}


function mkdliso_HyperStackOS_inchroot()
{
    MKISO_PATH=/home/mkiso_ARM64
    basedir=/usr1/EulerOS__ARM64
    PRODUCT="$1"
    CFG=custom/cfg_"`echo $PRODUCT | tr '[A-Z]' '[a-z]'`"
    ISO=$DVD_NAME
    ISOILP32=EulerOS-V3.0SP1-aarch64-ilp32-dvd.iso

    rm -f ./release_tmp ./release *.tar.gz
    cd ${basedir}
    sshscp_from "/srv/www/htdocs/$PRE_VERSION/$VERSION/release" .
    TAR_NAME=`cat release |awk -F / '{print $NF}'`
    TAR=${TAR_NAME%.tar.gz}

    thread_list=`ps -ef | grep mkdliso | grep -v grep | awk '{print $2}'`
    for id in `cat thread_list`
    do
        log_info "There has been several threads about mkdliso ,already. Killing..."
        kill 9 $id
    done

    rm -rf "$TAR" "$TAR_NAME"
    wget -q `cat release` &> /dev/null
    if [ $? -ne 0 ];then
        log_error "wget ${TAR_NAME} failed!"
    fi
    log_info "wget ${TAR_NAME} success!"

    tar xzf "$TAR_NAME"
    if [ $? -ne 0 ]
    then
        log_error "${TAR_NAME} unzip failed!"
    fi
    log_info "${TAR_NAME} unzip success!"
    rm -rf "$TAR_NAME"

    cd ${basedir}/"$TAR"
    mv repos/kernel repos/Update/
    mv repos/glibc-pkgs repos/Update/
    find repos/ -name *.rpm > repos/iso_package.list

    ./mkdliso -p "$PRODUCT" -c "$CFG"
    if [ $? -ne 0 ];then
        log_error "kiwi_iso failed!"
    fi
    log_info "kiwi iso success!"

    sshscp_from "/srv/www/htdocs/$PRE_VERSION/$VERSION/release_tmp" .
    if [ $? -ne 0 ];then
        log_error "wget release_tmp failed!"
    fi
    log_info "wget release_tmp success!"

    RELEASEDIR=`cat release_tmp`
    RELEASE_DIR="$RELEASEDIR/ISO"
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"

    cd result/20*
    create_checksum $ISO
    sshscp "$ISO $ISO${SHA256SUM}" "$RELEASE_DIR"

    chmod_http 'EulerOS_V200R008C00_ARM64'
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    log_info "Release $ISO to $IP:$RELEASE_DIR"

    return 0
}

function merge_release_html()
{
    set +e
    wget -q -c -r --level=1 -nd -np -k -L -p -A "*.html"  http://${IP}/${PRE_VERSION}/${VERSION}/ &> /dev/null
    set -e

    dst_html=dst.html
    if ! `ls release_*.html &> /dev/null`;then
        rm -f *.html
        echo "No html is avaliable !" > $dst_html
    else
        cat `ls release_*.html | head -n 1` > $dst_html
        win_line=`grep -n "Download on windows" $dst_html | awk -F ':' '{print $1}'`
        linux_line=`grep -n "Download on linux" $dst_html | awk -F ':' '{print $1}'`
        ((linux_line=$linux_line+1))
        for file in `ls release_*.html`
        do
            #skip the empty file
            contents=`cat $file`
            if [ "x$contents" == "x" ];then
                continue
            fi
            #exclude double link
            link=`cat $file | grep "Download on windows" | awk -F '"' '{print $2}'`
            tar_name=${link##*/}
            if cat $dst_html | grep $tar_name &> /dev/null;then
                continue
            fi
            link=`cat $file | grep "Download on linux" | awk -F '"' '{print $2}'`
            tar_name=${link##*/}
            if cat $dst_html | grep $tar_name &> /dev/null;then
                continue
            fi

            #insert new link
            win_link=`cat $file | grep "Download on windows"`
            linux_lik=`cat $file | grep "Download on linux"`
            sed -i "$win_line a$win_link" $dst_html
            sed -i "$linux_line a$linux_lik" $dst_html
            ((win_line=$win_line+1))
            ((linux_line=$linux_line+2))
        done
    fi
    CMD="rm -f ${HTTP_DIR}/${PRE_VERSION}/${VERSION}/release_*.html"
    sshcmd "$CMD"

    cat $dst_html > release.html
    sshscp release.html ${HTTP_DIR}/${PRE_VERSION}/${VERSION}/
    set +e
    SSH_CMD="chmod 755 ${HTTP_DIR}/${PRE_VERSION}/${VERSION}/release.html"
    sshcmd "$SSH_CMD"
    set -e
    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
    rm -f *.html
}


function make_docker_image()
{
    chroot_run "cd /home; bash make_version.sh make_docker_image_inchroot"
}


. "$CPATH/make_docker_image.sh"


function make_vm_qcow2()
{
    chroot_run "cd /home; bash make_version.sh make_vm_qcow2_inchroot"
}

function make_vm_qcow2_inchroot()
{
    remoteip=10.175.112.72
    remoteroot=root
    remotepwd=EulerLinux
    qcow2_image_dir=qcow2_image
    basedir=/home/V3R1/arm64_make_qcow2/arm64_standard
    remote_img_dir="${basedir}/qcow2_image"

    # remote build
    sh ./tools/sshcmd.sh -c "rm -rf $basedir;mkdir -p $basedir" -m ${remoteip} -u ${remoteroot} -p ${remotepwd}

    # mount iso for repo
    release_dir=`get_release_dir`
    set +e

    sh ./tools/sshscp.sh -d ${remoteip}:$basedir/ -s $(pwd)  -p ${remotepwd} -r
    sh ./tools/sshcmd.sh -c "cd $basedir/local_script; sed -i \"0,/STARTTIME/ s/STARTTIME/#STARTTIME/\" make_version.sh; \
                             sed -i \"0,/exec/ s/exec/#exec/\" make_version.sh;bash make_version.sh make_vm_qcow2_main" \
                              -m ${remoteip} -u ${remoteroot} -p ${remotepwd}
    set -e

    # upload
    rm -rf $qcow2_image_dir
    mkdir $qcow2_image_dir
    RELEASE_DIR="${release_dir}/${SUB_RELEASE_DIR}/"
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"

    sh "$TOOLS"/safe_sshscp.sh -p $remotepwd -s "$remoteip:$remote_img_dir/*.qcow2" -d $qcow2_image_dir -r
    sh "$TOOLS"/safe_sshscp.sh -p $remotepwd -s "$remoteip:$remote_img_dir/*.qcow2${SHA256SUM}" -d $qcow2_image_dir -r
    cd $qcow2_image_dir
    qcow2_img=`ls *.qcow2`
    qcow2_256=`ls *.qcow2${SHA256SUM}`

    sshscp "${qcow2_img} ${qcow2_256}" "$RELEASE_DIR"
    if [ $? -ne 0 ]; then
        log_error "Failed upload qcow2"
    fi
    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi

    log_info "Release ${qcow2_img} ${qcow2_256} to $IP:$RELEASE_DIR"
}

function make_upgrade_patch_inchroot()
{
    [ -f ./release ] && rm -f ./release
    sshscp_from "$HTTP_DIR/$PRE_VERSION/$VERSION/release" "./" &> /dev/null
    http_path_tar=$(cat ./release)
    if [ "${ISCI}" -eq "0" ]; then
        remte_path_tar="${HTTP_DIR}/${http_path_tar#http://${IP}*}"
        version_tar=${remte_path_tar##*/}
    else
        remte_path_tar="${HTTP_DIR}/internal_use_only${http_path_tar#*internal_use_only}"
        version_tar=${remte_path_tar##*/}
    fi
    if ls *.tar.gz &> /dev/null; then
        rm -f *.tar.gz
    fi
    sshscp_from "$remte_path_tar" "./" &> /dev/null
    upgrade_patch_dir="EulerOS_UpgradePatch"
    [ -d ./"$upgrade_patch_dir" ] && rm -rf "$upgrade_patch_dir"
    mkdir "$upgrade_patch_dir"
    euleros_upgrade_path="${CPATH}/euleros-upgrade"
    [ -d "${euleros_upgrade_path}" ] && rm -rf "${euleros_upgrade_path}"
    mkdir "${euleros_upgrade_path}"
    cd "${euleros_upgrade_path}"
    wget -q -r -l1 -nd -A 'euleros-upgrade-1*.noarch.rpm' "${OBS_CUSTOM_URL}noarch/"
    rpm2cpio euleros-upgrade-1.*.noarch.rpm | cpio -id
    cd -
    cp "${euleros_upgrade_path}/do_patch.sh" ./
    bash do_patch.sh "${euleros_upgrade_path}" "${CPATH}/${version_tar}" "${CPATH}/${version_tar}" "${CPATH}/${upgrade_patch_dir}"

    RELEASEDIR=$(get_release_dir)
    RELEASE_DIR="${RELEASEDIR}/${SUB_RELEASE_DIR}/"
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"
    sshscp "${CPATH}/${upgrade_patch_dir}" "$RELEASE_DIR"
    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
}

function make_upgrade_patch()
{
    chroot_run "cd /home; bash make_version.sh make_upgrade_patch_inchroot"
}

function make_cmc_scmInfo()
{
    RELEASEDIR=`get_release_dir`
    CMC_VERSION_FILENAME=`echo "$RELEASEDIR" | awk -F "/" '{print $NF}'`
    CMC_VERSION_TIME1="${CMC_VERSION_FILENAME#*-}"
    CMC_VERSION_TIME=`echo "${CMC_VERSION_TIME1}" | awk -F "-" '{print $1"."$2"."$3"."$4$5$6}'`
    Dependency_path="${CPATH}/../../conf"
    versionType=`grep 'versionType' ${Dependency_path}/Dependency.xml | awk -F "[><]" '{print $3}' | head -n 1`
    versionName=`grep 'componentName' ${Dependency_path}/Dependency.xml | awk -F "[><]" '{print $3}' | head -n 1`
    source_name="${Dependency_path}/${versionName}_src.xml"
    set +e
    sed -i "s/Version_time/${CMC_VERSION_TIME}/g" $Dependency_path/Dependency.xml
    set -e
    obs_meta_dir="$CPATH/../../../../../obs_meta"
    PRJS=`cat service_list.xml | grep 'project name' | awk -F'"' '{print $2}' | sort | uniq`
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > ${source_name}
    echo "<Results>" >> ${source_name}
    echo "    <versionType>${versionType}</versionType>" >> ${source_name}
    echo "    <Offering>PIA</Offering>" >> ${source_name}
    echo "    <name>${versionName}</name>" >> ${source_name}
    echo "    <version>${CMC_VERSION_TIME}</version>" >> ${source_name}
    echo "    <dependentSourceFiles>" >> ${source_name}
    for prj in $PRJS
    do
        cat $obs_meta_dir/projects/$prj/.osc/_sources | sort -k3 -u | while read line
        do
            scm=`echo $line | awk -F'"' '{print $4}'`
            sources=`echo $line | awk -F'"' '{print $6}'`
            branch=`echo $line | awk -F'"' '{print $8}'`
            tag=`echo $line | awk -F'"' '{print $10}'`
            if [ "$scm" == "git" ]; then
                localpath=`basename $sources | awk -F'.git' '{print $1}'`
                echo "        <fileidentify revision=\"$tag\" localpath=\"$localpath\" repoBase=\"$sources\" branch=\"$branch\">" >> ${source_name}
                echo "        </fileidentify>" >> ${source_name}
            elif [ "$scm" == "svn" ]; then
                echo "        <fileidentify revision=\"$tag\" localpath=\"`basename $sources`\" repoBase=\"$sources\">" >> ${source_name}
                echo "        </fileidentify>" >> ${source_name}
            elif [ "$scm" == "repo" ]; then
                if echo $sources | grep CRDU_EULEROS_GIT &>/dev/null; then
                    url="http://dgggit09-rd.huawei.com/a/$sources"
                else
                    url="ssh://euleros-review.huawei.com:29418/$sources"
                fi
                echo "        <fileidentify revision=\"$tag\" localpath=\"$sources\" repoBase=\"$url\" branch=\"$branch\">" >> ${source_name}
                echo "        </fileidentify>" >> ${source_name}
            fi
        done
    done
    echo "    </dependentSourceFiles>" >> ${source_name}
    echo "</Results>" >> ${source_name}
}


function make_cmc_file()
{
    cmc_LCRP="${CMC_BASEDIR}/LCRP_HOME"
    LCRP_FILE="LCRP_HOME.zip"
    [[ -f ${CMC_BASEDIR}/$LCRP_FILE ]] && rm -rf ${CMC_BASEDIR}/$LCRP_FILE*
    if [ ! -d $cmc_LCRP ];then
        cd ${CMC_BASEDIR}
        wget "http://$IP/CMC_LCRP/${LCRP_FILE}"
        unzip $LCRP_FILE
        cd -
    fi
    sed -i "s#`grep userName $cmc_LCRP/conf/Setting.xml`#<userName>zwx365138</userName>#g" $cmc_LCRP/conf/Setting.xml
    sed -i "s#`grep password $cmc_LCRP/conf/Setting.xml`#<password>wsx@1qaz</password>#g" $cmc_LCRP/conf/Setting.xml

    cmc_dir="${CMC_BASEDIR}/up_file"
    cmc_upfile_dir="${CMC_BASEDIR}/up_file/aarch64"
    Dependency_path="${CPATH}/../../conf"
    LCRP_path="$cmc_LCRP/bin"
    [[ -d $cmc_dir ]] || mkdir -p $cmc_dir
    [[ -d $cmc_upfile_dir ]] && rm -rf $cmc_upfile_dir
    mkdir -p $cmc_upfile_dir
    RELEASEDIR=`get_release_dir`
    CMC_VERSION_FILENAME=`echo "$RELEASEDIR" | awk -F "/" '{print $NF}'`
    CMC_VERSION_TIME1="${CMC_VERSION_FILENAME#*-}"
    CMC_VERSION_TIME=`echo "${CMC_VERSION_TIME1}" | awk -F "-" '{print $1"."$2"."$3"."$4$5$6}'`
    sshscp_from "$RELEASEDIR/Software/*" "$cmc_upfile_dir" &> /dev/null
    if [ $? -ne 0 ]; then
        rm -rf $cmc_upfile_dir
        log_error "Failed on sshscp_from $RELEASEDIR/Software/01.InstallationPackage $cmc_upfile_dir"
    fi
    set +e
    if [ -d $cmc_upfile_dir/EulerOS_UpgradePatch/Tools ];then
        rm -rf $cmc_upfile_dir/EulerOS_UpgradePatch/Tools/CE-PATCH-*
    fi
    set -e
    sed -i "s/Version_time/${CMC_VERSION_TIME}/g" $Dependency_path/Dependency.xml
    sh $LCRP_path/lcrp.sh d $Dependency_path/Dependency.xml
    if [ $? -ne 0 ]; then
        rm -rf $cmc_upfile_dir
        log_error "Failed on download file!"
    fi
    sh $LCRP_path/lcrp.sh u $Dependency_path/Dependency.xml
    if [ $? -ne 0 ]; then
        rm -rf $cmc_upfile_dir
        log_error "Failed on upload file!"
    fi
    rm -rf $cmc_upfile_dir
}


function repodata_check()
{
    set +e
    base_repo=${CPATH}/repo_conf/EulerOS-base.repo
    #just check update project on obs
    #if the repo of update is invalid, delete the update's info
    grep "\/Update\/" ${CPATH}/repo_conf/ -inR | while read yum_conf
    do
        file=`echo "$yum_conf" | awk -F ':' '{print $1}'`
        line=`echo "$yum_conf" | awk -F ':' '{print $2}'`
        obs_url=`echo "$yum_conf" | awk -F '=' '{print $2}'`
        wget -q ${obs_url}repodata/repomd.xml -O repomd_test.xml
        if [ $? -ne 0 ];then
            if [ "${file##*.}" == "repo" ];then
                cat $base_repo >  $file
            elif [ "${file##*.}" == "conf" ];then
                let line_down=line+2
                let line_up=line-2
                sed -i "${line_up},${line_down}d" $file
                sed -i "/Update/d" ${CPATH}/repo_conf/RepositoryRule.conf
            fi
        else
            rm -f repomd_test.xml
        fi
    done
    set -e
}
function make_upload_cmc_image()
{
    Dependency_path="${CPATH}/../../conf"
    RELEASEDIR=`get_release_dir`
    CMC_VERSION_FILENAME=`echo "$RELEASEDIR" | awk -F "/" '{print $NF}'`
    CMC_VERSION_TIME1="${CMC_VERSION_FILENAME#*-}"
    CMC_VERSION_TIME=`echo "${CMC_VERSION_TIME1}" | awk -F "-" '{print $1"."$2"."$3"."$4$5$6}'`
    sed -i "s/Version_time/${CMC_VERSION_TIME}/g" ./product_version.conf
    versionName=`grep 'componentName' ${Dependency_path}/Dependency.xml | awk -F "[><]" '{print $3}' | head -n 1`
    sed -i "s/Product_version/${versionName}/g" ./push_envImage_to_cmc.py
    python ./push_envImage_to_cmc.py
}

function make_images_slim()
{
    cd ../../../../../
    IMAGES_SLIM=images-slim.tar.gz
    if [ -f "$IMAGES_SLIM" ]; then
        rm -rf $IMAGES_SLIM
    fi
    rm -rf IMAGES_SLIM${SHA256SUM}

    # Change file permission mode to meet security needs
    set +e
    chmod 600 image-slim/Dockerfile
    chmod 700 image-slim/image-slim.sh
    chmod 600 image-slim/README
    chmod 600 image-slim/slim.json
    chmod 600 image-slim/slim.repo
    chmod 700 image-slim/slim.sh
    chmod 700 image-slim/tailor-post.sh
    chmod 700 image-slim/tailor.py
    set -e
    # fix bep check
    rm -rf image-slim/.git

    tar czf "$IMAGES_SLIM" image-slim
    create_checksum "$IMAGES_SLIM"
    RELEASEDIR=`get_release_dir`
    RELEASE_DIR="$RELEASEDIR/$SUB_RELEASE_DIR/DockerStack/"
    SSH_CMD="mkdir -p $RELEASE_DIR"
    sshcmd "$SSH_CMD"
    sshscp "$IMAGES_SLIM $IMAGES_SLIM${SHA256SUM}" "$RELEASE_DIR"
    chmod_http
    if [ $? -ne 0 ]; then
        log_error "Failed in chmod_http"
    fi
}

. "$CPATH/make_vm_qcow2.sh"
. "$CPATH/make_tools/make_tools.sh"
. "$CPATH/make_gcov.sh"

